package com.leyou.sms.listener;

import com.leyou.common.constants.MQConstants;
import com.leyou.common.constants.MQConstants.RoutingKey;
import com.leyou.sms.config.SmsProperties;
import com.leyou.sms.utils.SendSmsUtils;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SmsListener {

    @Autowired
    SendSmsUtils sendSmsUtils;

    @RabbitListener(bindings = @QueueBinding(
            value =@Queue(value = MQConstants.Queue.SMS_VERIFY_CODE_QUEUE, declare = "true"),
            exchange =@Exchange(value = MQConstants.Exchange.SMS_VERIFY_CODE_QUEUE,type = ExchangeTypes.TOPIC),
            key = RoutingKey.VERIFY_CODE_KEY
    ))
    public void listenVerifyCode(Map<String,String> msg){
        String phone = msg.get("phone");
        String code = msg.get("code");
        sendSmsUtils.sendCheckCodeUtils(phone, code);
    }

}
